package com.gopay.common.cps.manager.gsrt.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.cps.dao.gsrt.GsrtAccountRechargeDao;
import com.gopay.common.cps.manager.gsrt.GsrtAccountRechargeQueryManager;
import com.gopay.common.domain.gsrt.GsrtAccountRecharge;
/**
 * 
 * G商融通充值查询manager实现
 * @author zyt
 * @2016年4月19日 @上午11:23:57
 *
 */
@Service("gsrtAccountRechargeQueryManager")
public class GsrtAccountRechargeQueryManagerImpl implements GsrtAccountRechargeQueryManager {
	
	@Resource(name = "gsrtAccountRechargeDao")
	private GsrtAccountRechargeDao gsrtAccountRechargeDao;
	
	 private final String FIND_TIMEOUT_ORDER_BY_PAGE_TIMESPAN_SQL = "SELECT  c.id  FROM GSRT_ACCOUNT_RECHARGE C "
				+ "  where(C.TXN_STA_CD = '30001'"
				+ " AND ROUND(TO_NUMBER(SYSDATE - (C.CREATED_TS+0))*24*60) >= :timeSpan) ";
	    
	 
	 private final String FIND_TIMEOUT_ORDER_BY_TIMESPAN_SQL = "SELECT  c.gopayOrderId  FROM GSRT_ACCOUNT_RECHARGE C "
				+ "  where(C.TXN_STA_CD = '30000'"
				+ " AND ROUND(TO_NUMBER(SYSDATE - (C.CREATED_TS+0))*24*60) >= :timeSpan) ";

	@Override
	public List<GsrtAccountRecharge> getByGopayOrderId(String gopayOrderId) {
		String hql=" from GsrtAccountRecharge where gopayOrderId=:gopayOrderId ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("gopayOrderId", gopayOrderId);
		List<GsrtAccountRecharge> list=gsrtAccountRechargeDao.findByHql(hql, param);
		return list;
	}

	@Override
	public List<GsrtAccountRecharge> getByMerIdAndMerOrderId(String merId, String merOrderId) {
		String hql=" from GsrtAccountRecharge where merCustId=:merId and  merOrderId=:merOrderId";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("merId", merId);
		param.put("merOrderId", merOrderId);
		List<GsrtAccountRecharge> list=gsrtAccountRechargeDao.findByHql(hql, param);
		return list;
	}

	@Override
	public List<Object> findTimeoutListByTimeSpan(int timeSpan) {
		Map m = new HashMap();
		m.put("timeSpan", timeSpan);
		List<?> result = gsrtAccountRechargeDao.findBySql(FIND_TIMEOUT_ORDER_BY_PAGE_TIMESPAN_SQL, m);
		return (List<Object>) result;
	}

	@Override
	public GsrtAccountRecharge findByTransDtlSq(Long transDtlSq) {
		String hql=" from GsrtAccountRecharge where transDtlSq=:transDtlSq ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("transDtlSq", transDtlSq);
		List<GsrtAccountRecharge> list=gsrtAccountRechargeDao.findByHql(hql, param);
		if(list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

}
